function AjaxPostBack(evalString)
{
	var prm = Sys.WebForms.PageRequestManager.getInstance();
	if (prm.get_isInAsyncPostBack())
	{
		setTimeout('AjaxPostBack("' + evalString + '")', 300);
	}
	else
	{
		eval(evalString);
	}
}
function ShowDialog(dialogId, closeButtonId, maskId, onLoadDialog, onCloseDialog, left, top, closeAsClick)
{
	var showDialogObj = $("#" + dialogId).overlay(
	{
		closeOnClick: closeAsClick ? closeAsClick : false,
		left: left ? left : "center",
		top: top ? top : "center",
		close: closeButtonId ? "#" + closeButtonId : null,
		expose:
		{
			color: '#000000',
			maskId: maskId ? maskId : null,
			loadSpeed: 1,
			closeSpeed: 1,
			opacity: 0.85,
			onLoad: onLoadDialog,
			onClose: onCloseDialog
		},
		api: true
	}).load();
	return showDialogObj;
}
function ShowPage(pageDialogId, pageURL, width, height, timeout, closeButtonId, closeAsClick)
{
	if (width < 0)
		width = GetBodyMaxWidth() + width;
	else
		width = GetBodyMaxWidth(width);
	if (height < 0)
		height = GetBodyMaxHeight() + height;
	else
		height = GetBodyMaxHeight(height);
	$("#" + pageDialogId + " iframe").attr("src", "about:blank").css("width", width + "px").css("height", height + "px");
	setTimeout('$("#' + pageDialogId + ' iframe").attr("src", "' + pageURL + '")', timeout != null ? timeout : 300);
	return ShowDialog(pageDialogId, closeButtonId, null, null, null, null, null, closeAsClick);
}
function ShowPage_v2(pageDialogId, pageURL, width, height, timeout, markColor, markAlpha, closeButtonId, closeAsClick)
{
	if (width < 0)
		width = GetBodyMaxWidth() + width;
	else
		width = GetBodyMaxWidth(width);
	if (height < 0)
		height = GetBodyMaxHeight() + height;
	else
		height = GetBodyMaxHeight(height);
	$("#" + pageDialogId + " iframe").attr("src", "about:blank").css("width", width + "px").css("height", height + "px");
	setTimeout('$("#' + pageDialogId + ' iframe").attr("src", "' + pageURL + '")', timeout != null ? timeout : 300);

	var showDialogObj = $("#" + pageDialogId).overlay(
	{
		closeOnClick: closeAsClick,
		left: "center",
		top: "center",
		close: closeButtonId ? "#" + closeButtonId : null,
		expose:
		{
			color: markColor ? markColor :'#000000',
			loadSpeed: 1,
			closeSpeed: 1,
			opacity: markAlpha ? markAlpha : 0
		},
		api: true
	}).load();

	return showDialogObj;
}
function DisableTextSelect(obj)
{
	if ($.browser.mozilla)
	{//Firefox
		$(obj).css('MozUserSelect', 'none');
	} else if ($.browser.msie)
	{//IE
		$(obj).bind('selectstart', function() { return false; });
	} else
	{//Opera, etc.
		$(obj).mousedown(function() { return false; });
	}
}
function OpenWindow(theURL, winName, features, w, h, scrollbars, center, x, y)
{
	if (w == null || w == 0)
		w = window.screen.availWidth;
	else
		if (w < 0)
		w = window.screen.availWidth + (w * 2);
	if (h == null || h == 0)
		h = window.screen.availHeight;
	else
		if (h < 0)
		h = window.screen.availHeight + (h * 2);

	var l = window.screen.availWidth / 2 - (w / 2);
	l = l > 0 ? l : 1;
	if (x != null)
		l = x;

	var t = window.screen.availHeight / 2 - (h / 2);
	t = t > 0 ? t : 1;
	if (y != null)
		t = y;

	var win = window.open(theURL, winName, features + ",toolbar=0,location=1,status=1,menubar=0,resizable=1,width=" + (w - 12) + ",height=" + (h - 64) + (scrollbars != null && scrollbars ? ",scrollbars=1" : "") + (center == null || center ? ",left=" + l + ",top=" + t : ""));
	if (x != null && y != null)
		win.moveTo(x, y);
	else
		if (center == false)
			win.moveTo(1, 1);
	if (w != 1 && h != 1)
		win.resizeTo(w, h);
	return win;
}
function ResizeWindow(w, h, scrollbars, center)
{
	if (w == null || w < 1)
		w = window.screen.availWidth;
	if (h == null || h < 1)
		h = window.screen.availHeight;
	var l = window.screen.availWidth / 2 - (w / 2);
	l = l > 0 ? l : 1;
	var t = window.screen.availHeight / 2 - (h / 2);
	t = t > 0 ? t : 1;
	if (center == null || center == true)
		window.moveTo(l, t);
	window.resizeTo(w, h);
	if (center == null || center == true)
		window.moveTo(l, t);
}
function FireDefaultButton(event, targetId)
{
	if (event.keyCode == 13)
	{
		var src = event.srcElement || event.target;
		if (!src || src.tagName.toLowerCase() != "textarea")
		{
			var defaultButton = document.getElementById(targetId);
			if (defaultButton && (typeof defaultButton.onclick != "undefined" || typeof defaultButton.href != "undefined"))
			{
				if (typeof defaultButton.onclick != "undefined" && defaultButton.onclick != null)
				{
					var returnValue = defaultButton.onclick();
					if (returnValue == false)
						return false;
				}
				if (typeof defaultButton.href != "undefined" && defaultButton.href != null)
				{
					var returnValue = eval(defaultButton.href);
					if (returnValue == false)
						return false;
				}
				event.cancelBubble = true;
				if (event.stopPropagation)
				{
					event.stopPropagation();
				}
				return false;
			}
		}
	}
	return true;
}
function CheckKeyPressAndRun(event, keyCode, evalString)
{
	var event = event ? event : window.event;
	var key = event.keyCode ? event.keyCode : event.which;
	if (key == keyCode)
		return eval(evalString);
};
function GetBodyMaxHeight(defaultHeight)
{
	var maxHeight = document.body.clientHeight;
	if (defaultHeight == null)
		return maxHeight;
	if (defaultHeight <= maxHeight)
		return defaultHeight;
	else
		return maxHeight;
}
function GetBodyMaxWidth(defaultWidth)
{
	var maxWidth = document.body.clientWidth;
	if (defaultWidth == null)
		return maxWidth;
	if (defaultWidth <= maxWidth)
		return defaultWidth;
	else
		return maxWidth;
}
function GetBody()
{
	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}
function GetObj(id)
{
	return document.getElementById(id);
}
function ShowDiv(divId, show, x, y, allwayShow)
{
	var objDiv = document.getElementById(divId);
	if (objDiv == null)
		return;

	if (show == null)
		if (objDiv.style.display == "")
		objDiv.style.display = "none";
	else
		objDiv.style.display = "";
	else
		if (show == false)
		objDiv.style.display = "none";
	else
		objDiv.style.display = "";

	if (x != null && y != null)
	{
		if (allwayShow)
		{
			var winwidth = GetBody().scrollLeft;
			var winheight = GetBody().scrollTop;
			if (x + objDiv.offsetWidth - GetBody().scrollLeft > winwidth)
				x = x - objDiv.offsetWidth - 20;
			if (y + objDiv.offsetHeight - GetBody().scrollTop > winheight)
				y = y - objDiv.offsetHeight - 20;
		}
		objDiv.style.left = x + "px";
		objDiv.style.top = y + "px";
	}
}
function ShowDivAtMouse(event, divId, dx, dy, allwayShow)
{
	var curX = event.clientX + GetBody().scrollLeft;
	var curY = event.clientY + GetBody().scrollTop;
	if (dx == null)
		dx = 0;
	if (dy == null)
		dy = 0;
	ShowDiv(divId, true, curX + dx, curY + dy, allwayShow);
}

function ShowDivByObj(divId, obj, timeoutObj)
{
	var position = GetOffsetPosition(obj);
	ShowDiv(divId, true, position[0] + obj.offsetWidth, position[1]);
	var divObj = document.getElementById(divId);
	var divMouseover = function() { clearTimeout(timeoutObj); };
	var divMouseout = function() { timeoutObj = setTimeout("ShowDiv('" + divId + "', false)", 200); };
	if (document.all)
	{
		obj.attachEvent("onmouseover", divMouseover);
		obj.attachEvent("onmouseout", divMouseout);

		divObj.attachEvent("onmouseover", divMouseover);
		divObj.attachEvent("onmouseout", divMouseout);
	}
	else
	{
		obj.addEventListener("mouseover", divMouseover, false);
		obj.addEventListener("mouseout", divMouseout, false);

		divObj.addEventListener("mouseover", divMouseover, false);
		divObj.addEventListener("mouseout", divMouseout, false);
	}
}

function AddEventMouseOverOutToObj(divId, objId, showFunctionNameEval, hideFunctionNameEval, timeOut)
{
	eval(showFunctionNameEval + "('" + divId + "','" + objId + "')");
	var obj = document.getElementById(objId);
	var divObj = document.getElementById(divId);
	window[divId + "_" + objId] = null;
	var timeoutObj = window[divId + "_" + objId];
	var divMouseover = function() { clearTimeout(timeoutObj); };
	var divMouseout = function () { timeoutObj = setTimeout(hideFunctionNameEval + "('" + divId + "','" + objId + "')", (timeOut == null ? 400 : timeOut)); };
	if (document.all)
	{
		obj.attachEvent("onmouseover", divMouseover);
		obj.attachEvent("onmouseout", divMouseout);

		divObj.attachEvent("onmouseover", divMouseover);
		divObj.attachEvent("onmouseout", divMouseout);
	}
	else
	{
		obj.addEventListener("mouseover", divMouseover, false);
		obj.addEventListener("mouseout", divMouseout, false);

		divObj.addEventListener("mouseover", divMouseover, false);
		divObj.addEventListener("mouseout", divMouseout, false);
	}
}

function GetOffsetPosition(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
		do
	{
		curleft += obj.offsetLeft;
		curtop += obj.offsetTop;
	}
	while (obj = obj.offsetParent);
	return [curleft, curtop];
}

function AlphaEffect(divId, startAlpha, endAlpha, step)
{
	var alpha;
	if (startAlpha < endAlpha)
	{
		startAlpha = startAlpha + step;
		if (startAlpha > endAlpha)
			startAlpha = endAlpha;
		alpha = startAlpha;
	}
	else
		if (startAlpha > endAlpha)
	{
		startAlpha = startAlpha - step;
		if (startAlpha < endAlpha)
			startAlpha = endAlpha;
		alpha = startAlpha;
	}
	var style = document.getElementById(divId).style;
	style.display = "";
	style.filter = "Alpha(opacity=" + alpha + ")";
	style.opacity = alpha != 100 ? "0." + alpha : "1";

	if (startAlpha != endAlpha)
		setTimeout("AlphaEffect('" + divId + "', " + startAlpha + ", " + endAlpha + ", " + step + ")", 1);
	else
		if (startAlpha == endAlpha && startAlpha == 0)
		style.display = "none";
}

function ShowOverlay(show, zIndex, objOverlayId)
{
	objOverlayId = objOverlayId ? objOverlayId : "divOverlay";
	var obj = document.getElementById(objOverlayId);
	if (obj == null)
	{
		var divOverlay = document.createElement("div");
		divOverlay.innerHTML = '<div id="' + objOverlayId + '" style="background-color: #000000; opacity: 0.75; filter: alpha(opacity=75); position: absolute; left: 0px; top: 0px; display: none; z-index: ' + (zIndex ? zIndex : 0) + '"></div>';
		theForm.appendChild(divOverlay);
	}
	else
	{
		obj.style.zIndex = zIndex ? zIndex : 0;
		obj.style.position = "absolute";

		obj.style.backgroundColor = "#000000";
		obj.style.left = "0px";
		obj.style.top = "0px";
		obj.style.display = "none";

		if (document.all)
		{
			obj.style.setAttribute("filter", 'alpha(opacity=75)');
		}
		else
		{
			obj.style.opacity = "0.75";
		}
	}
	obj = document.getElementById(objOverlayId);

	obj.style.width = GetBody().scrollWidth + "px";
	obj.style.height = GetBody().scrollHeight + "px";
	if (show == true)
	{
		obj.style.display = "";
	}
	else
	{
		obj.style.display = "none";
	}
}

function LoadPage(url, show, width, height, zIndex, scrollBar)
{
	if (window["divLoadPageIndex"] == null)
		window["divLoadPageIndex"] = 0;

	divLoadPageIndex += 1;
	var frameName = "fLoadPage" + divLoadPageIndex;
	var divLoadPage = document.getElementById("divLoadPage");
	if (divLoadPage == null)
	{
		var divLoadPageObj = document.createElement("div");
		divLoadPageObj.innerHTML += '<div id="divLoadPage" style="position: absolute; left: 0px; top: 0px; width: auto; height: auto; display: none; z-index: ' + (zIndex ? zIndex : 1) + ';">' +
									'<iframe id="' + frameName + '" src="about:blank" name="' + frameName + '" width="1" height="1" frameborder="0" marginheight="0" marginwidth="0" style="background-color:#ffffff;" ' + (scrollBar != true ? 'scrolling="no"' : '') + '></iframe>' +
								'</div>';
		document.body.appendChild(divLoadPageObj);
		divLoadPage = document.getElementById("divLoadPage");
	}
	if (url == null || show == false)
	{
		//AlphaEffect("divLoadPage", 50, 0, 5);

		//		divLoadPage.style.display = "none";

		setTimeout('document.getElementById("divLoadPage").parentNode.parentNode.removeChild(document.getElementById("divLoadPage").parentNode); ShowOverlay(false);', 100);

		//		if (url == null)
		//			url = "about:blank";
		//		setTimeout("window.frames['" + frameName + "'].location = '" + url + "'", 500);
	}
	else
	{
		ShowOverlay(true);

		divLoadPage.style.display = "";

		var fLoadPage = window.frames[frameName];

		if (width != null)
			fLoadPage.frameElement.width = width;
		if (height != null)
			fLoadPage.frameElement.height = height;
		fLoadPage.location = url;

		//AlphaEffect("divLoadPage", 50, 100, 5);

		divLoadPage.style.left = ((GetBody().clientWidth - divLoadPage.offsetWidth) / 2) + "px";
		divLoadPage.style.top = (GetBody().scrollTop + ((GetBody().clientHeight - divLoadPage.offsetHeight) / 2)) + "px";
	}
}

function LoadDiv(divId, show, width, height, margin, padding, overlayId)
{
	padding = padding ? padding : 0;
	margin = margin ? margin : 0;
	var objDiv = document.getElementById(divId);
	var theBody = GetBody();

	if (show == false)
	{
		objDiv.style.display = "none";
		ShowOverlay(false, null, overlayId);
		return;
	}

	ShowOverlay(true, null, overlayId);
	if (width == null)
	{
		width = theBody.offsetWidth - margin * 2;
		height = theBody.offsetHeight - margin * 2;
	}

	objDiv.style.display = "";
	objDiv.style.width = width + "px";
	objDiv.style.height = height + "px";
	objDiv.style.left = ((theBody.offsetWidth - width) / 2 - padding) + "px";
	objDiv.style.top = ((theBody.offsetHeight - height) / 2 - padding) + "px";
}

function SetSelectedValue(selectObjId, value)
{
	var selectObj = document.getElementById(selectObjId);
	selectObj.value = value;
}

function GetQueryString(queryStringName)
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i = 0; i < vars.length; i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == queryStringName)
			return pair[1];
	}
	return null;
}

function CheckCheckboxRadioByValue(name, value)
{
	var checkObjList = document.getElementsByName(name);
	if (checkObjList == null)
		return;

	for (var i = 0; i < checkObjList.length; i++)
		checkObjList[i].checked = (checkObjList[i].value == value.toString());
}

function GetValueOfSelectRadio(name)
{
	var checkObjList = document.getElementsByName(name);
	if (checkObjList == null)
		return null;

	for (var i = 0; i < checkObjList.length; i++)
		if (checkObjList[i].checked)
		return checkObjList[i].value;

	return null;
}

function GetFlashObj(movieName)
{
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? document.getElementById(movieName) : document[movieName];
}

function HideBodyScrollBar()
{
	document.body.scroll = "no"; // IE
	document.body.style.overflow = "hidden"; // Non IE
	document.documentElement.style.overflow = 'hidden'; // Non IE
}

function InsertCharAtCursor(myField, myValue)
{
	//IE support
	if (document.selection)
	{
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}

	//MOZILLA/NETSCAPE support
	else
	{
		if (myField.selectionStart || myField.selectionStart == '0')
		{
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			restoreTop = myField.scrollTop;
			myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
			myField.selectionStart = startPos + myValue.length;
			myField.selectionEnd = startPos + myValue.length;

			if (restoreTop > 0)
			{
				myField.scrollTop = restoreTop;
			}
		}
		else
		{
			myField.value += myValue;
		}
	}
}

function InterceptCharTabs(evt, control)
{
	key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
	if (key == 9)
	{
		InsertCharAtCursor(control, '\t');
		return false;
	}
	else
	{
		return key;
	}
}

// String Function

String.prototype.Trim = function()
{
	return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.LeftTrim = function()
{
	return this.replace(/^\s+/, "");
}
String.prototype.RightTrim = function()
{
	return this.replace(/\s+$/, "");
}

// ajax jquery
function AjaxBindOptions(_url, targetId, lastselected)
{
	var oTarget = $('#' + targetId);
	$.ajax(
 {
 	url: _url,
 	cache: false,
 	success: function(data)
 	{
 		oTarget.empty();
 		var options = eval(data);
 		if (typeof options == 'object')
 		{
 			$.each(options, function(i)
 			{
 				oTarget.append('<option value="' + this[1] + '">' + this[0] + '</option>');
 			});
 			if (lastselected)
 				oTarget.find("option:last").attr("selected", "true");
 		}
 	}
 });
}